<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <title>Aries登录页面</title>
    <!-- CSS -->
<#include "plugin.ftl"/>
</head>
<body>
<div id="app" v-cloak style="width: 60%;margin: 0 auto">
    <div class="headerLogo">
        <h1>Welcome to Aries-Dashboard</h1>
    </div>
    <div class="container" style="width: 480px; height: 200px;margin-top: 35px">
        <el-form :model="accountInfo" :rules="loginRules" ref="loginForm" label-width="90px">
            <el-form-item prop="username">
                <el-input placeholder="用户名" v-model.trim="accountInfo.username"></el-input>
            </el-form-item>
            <el-form-item prop="password">
                <el-input placeholder="密码" v-model.trim="accountInfo.password" type="password"
                          auto-complete="off"></el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="validLogin()" style="width: 120px">登录</el-button>
                <el-button @click="resetForm()">重置</el-button>
            </el-form-item>
        </el-form>
    </div>
</div>
<script>
    //创建 vue实例对象
    var app = new Vue({
        el: '#app',
        data: function () {
            return {
                //定义 存放url地址对象
                urls: {
                    loginUrl: '/v1/login',   //登录验证接口
                    redirectUrl: '/', //登录成功后，跳转接口
                },
                //定义 登录信息对象
                accountInfo: {
                    username: '',
                    password: ''
                },
                //定义 校验规则对象
                loginRules: {
                    username: [
                        {required: true, message: '请输入用户名', trigger: 'blur'}
                    ],
                    password: [
                        {required: true, message: '请输入密码', trigger: 'blur'}
                    ]
                }
            }
        },
        methods: {
            //登录
            validLogin: function () {
                this.$refs.loginForm.validate(function (valid) {
                    if (valid) {
                        var requestOptions = {
                            url: this.urls.loginUrl,
                            data: this.accountInfo
                        }
                        this.ccAjax(requestOptions).done(function (data) {
                            if (data.code === "0") {
                                window.location.href = this.urls.redirectUrl
                            } else {
                                this.$message(data.msg)
                            }
                        }.bind(this));
                    } else {
                        this.$message('请将表单填写完整');
                    }
                }.bind(this));
            },
            //重置
            resetForm: function () {
                this.$refs.loginForm.resetFields();
            }
        }
    });
</script>
<style>
    .headerLogo {
        margin-top: 79px;
    }
</style>
</body>
</html>